package paperToChaKanChengJi.adapter

import com.lancoo.znbkxx.teacher.aibkTestCoach.questionToEvaluation.AibkSingleQuesEvaluationActivity
import android.app.Activity
import androidx.lifecycle.Lifecycle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import kotlinx.android.synthetic.main.item_subject.view.*
import paperToChaKanChengJi.data.QuesScoreRate

/**
 * Created by Dadong on 2020/3/26
 * Describe:
 */
class ChildAdapter(
        val genreName: String,
        val layer: Int,
        val paperId: String,
        val typeNo: String,
        val activity: Activity,
        val lifecycle: Lifecycle,
        layoutResId: Int, data: MutableList<QuesScoreRate>
) : BaseQuickAdapter<QuesScoreRate, BaseViewHolder>(layoutResId, data) {
    override fun convert(helper: BaseViewHolder, item: QuesScoreRate?) {
        with(helper.itemView) {
            subject_ll.setBackgroundColor(helper.itemView.resources.getColor(R.color.cf2f2f2))
            subject_tv.text = item!!.SortIndex
            scoring_tv.text = item.TotalScore
            score_tv.text = item.AvgScore
            if (item.ScoreRate == "--") {
                rate_tv.text = item.ScoreRate
            } else {
                rate_tv.text = "${item.ScoreRate}%"
                when {
                    item.ScoreRate.toDouble() >= 85 -> {
                        rate_tv.setTextColor(helper.itemView.resources.getColor(R.color.c0ACD81))
                    }
                    item.ScoreRate.toDouble() >= 70 -> {
                        rate_tv.setTextColor(helper.itemView.resources.getColor(R.color.c5498FF))
                    }
                    item.ScoreRate.toDouble() >= 60 -> {
                        rate_tv.setTextColor(helper.itemView.resources.getColor(R.color.cFF9137))
                    }
                    else -> {
                        rate_tv.setTextColor(helper.itemView.resources.getColor(R.color.cF97878))
                    }
                }
            }
            duration_tv.text = item.AnswerLength
            subject_ll.setOnClickListener {
                AibkSingleQuesEvaluationActivity.launch(activity, paperId, item.QuesID, typeNo, genreName)
            }
        }
    }
}